<?php require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
$__areatitle[1]='Pagamento de Servicos';
$__areatitle[2]='Pagamento de Compras';
$_coltype[0]='';
$_coltype[1]='URG';
$_colmodo[1]='Enviar';
$_colmodo[2]='Pagar';

	$TotalPay = 0;
  MYTCONN();

  #$GETMM = $GLOBALS['MYT']->db_array("SELECT MIN(FraID) AS MIN, MAX(FraID) AS MAX
  #        FROM facturas IGNORE INDEX (IdxCli,Referencia,FraConta,Origen1,OrdenPago)
  #        WHERE FraFecha >= '{$_POST['extbnf_DateStart']}' AND FraFecha <= '{$_POST['extbnf_DateEnd']}'");
  #if(isset($GETMM[1])){
  $GET = $GLOBALS['MYT']->db_array("SELECT FraID,FraFechaIngreso,FraAlbaran,
  FraUrgente,FraARecibir,FraEnviado,FraCargo,FraTasa,FraBnfNombre,sg_Abreviatura AS FraStatus, FraModo,
  FraBnfDocType,FraBnfCedula,FraBancoID,FraCiudadSucursal,FraSucursal,FraTipoCuenta,FraCuenta,FraAdcID, FraAdcCota, FraAdcBem, FraAdcGroup, FraAdcIdentifier
   FROM facturas IGNORE INDEX (IdxCli,Referencia,Origen1,OrdenPago)
   INNER JOIN beneficiarioscuentas ON cb_Id = FraCtaBenef
          INNER JOIN beneficiarios ON BnfNumero = cb_Beneficiario
          INNER JOIN facturasextjoins ON FraID = FraExtID
   INNER JOIN hd_statusfacturas ON sg_ID = FraStatus
   LEFT OUTER JOIN facturas_adicional ON FraID = FraAdcID
   WHERE BnfNumExt = 1 AND FraFecha >= '{$_POST['extbnf_DateStart']}' AND FraFecha <= '{$_POST['extbnf_DateEnd']}' AND FraBnfCedula = '04124922000161'");
  #}else{
  # $GET[0]=0;
  #}
# AND (FraBnfNumero = {$_POST['extbnfAccount']} OR FraBnfCedula = '04124922000161')"); # problema com consulta por nbeneficario
	$CGET = $GET[0];
	$rsStr = '';
	for($g = 1;$g<=$CGET;$g++) {
		$TotalPay += $GET[$g]['FraARecibir'];
		$rsStr .= '['.$GET[$g]['FraID'].',\''.$_colmodo[$GET[$g]['FraModo']].'\','.$GET[$g]['FraAlbaran'].',\''.$GET[$g]['FraBnfNombre'].'\',
		\''.$GET[$g]['FraBnfDocType'].'\',\''.$GET[$g]['FraBnfCedula'].'\',\''.$GET[$g]['FraBancoID'].'\',\''.$GET[$g]['FraCiudadSucursal'].'\',
		\''.$GET[$g]['FraSucursal'].'\',\''.$GET[$g]['FraTipoCuenta'].'\',\''.$GET[$g]['FraCuenta'].'\',\''.$GET[$g]['FraAdcCota'].'\',\''.$GET[$g]['FraAdcBem'].'\',\''.$GET[$g]['FraAdcGroup'].'\',
		'.number_format($GET[$g]['FraTasa'],4,'.','').','.number_format($GET[$g]['FraCargo'],2,'.','').','.number_format($GET[$g]['FraEnviado'],2,'.','').',
		'.number_format($GET[$g]['FraARecibir'],2,'.','').',\''.$GET[$g]['FraFechaIngreso'].'\',\''.$_coltype[$GET[$g]['FraUrgente']].'\',\''.$GET[$g]['FraStatus'].'\'],';
	} 
?>

<div id="rsDisplay"></div>
<script charset="utf-8" type="text/javascript">
disableSelection(document.getElementById("rsDisplay"))

Ext.onReady(function(){

 $elem = 185;
 var  windowWidth = 0, windowHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
	windowWidth = window.innerWidth
	windowHeight = window.innerHeight-$elem;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	windowWidth = document.documentElement.clientWidth;
	windowHeight = document.documentElement.clientHeight-$elem;
  } 

    Ext.QuickTips.init();

    var myData = [<?php echo substr($rsStr,0,strlen($rsStr)-1);?>];

    var ds = new Ext.data.Store({
        reader: new Ext.data.ArrayReader({}, [
		   {name: 'FraID', type: 'int'},
		   {name: 'FraModo', type: 'string'},
		   {name: 'FraAlbaran', type: 'float'},
		   {name: 'FraBnfNombre', type: 'string'},
		   {name: 'FraBnfDocType', type: 'string'},
		   {name: 'FraBnfCedula', type: 'string'},
		   {name: 'FraBancoID', type: 'string'},
		   {name: 'FraCiudadSucursal', type: 'string'},
		   {name: 'FraSucursal', type: 'string'},
		   {name: 'FraTipoCuenta', type: 'string'},
		   {name: 'FraCuenta', type: 'string'},
		   {name: 'FraAdcCota', type: 'string'},
		   {name: 'FraAdcBem', type: 'string'},
		   {name: 'FraAdcGroup', type: 'string'},
		   {name: 'FraTasa', type: 'float'},
		   {name: 'FraCargo', type: 'float'},
		   {name: 'FraEnviado', type: 'float'},
		   {name: 'FraARecibir', type: 'float'},
		   {name: 'Data', type: 'date', dateFormat: 'Y-m-d H:i:s'},
		   {name: 'FraUrgente', type: 'string'},
		   {name: 'FraStatus', type: 'string'}
        ])
    });
    ds.loadData(myData);
    var colModel = new Ext.grid.ColumnModel([
        {header: "Operacao", width: 60, sortable: true, locked:true, dataIndex: 'FraID'},
        {header: "Canal", width: 60, sortable: true, dataIndex: 'FraModo'},
        {header: "N. Guia", width: 75, sortable: true, locked:true, align: 'right', dataIndex: 'FraAlbaran'},
        {header: "Destinatario", width: 150, sortable: true, locked:true, dataIndex: 'FraBnfNombre'},
        {header: "Tipo Doc", width: 50, sortable: true, locked:true,dataIndex: 'FraBnfDocType'},
        {header: "N Identificacao", width: 80, sortable: true, locked:true, align: 'right',dataIndex: 'FraBnfCedula'},
        {header: "Banco Pagamento", width: 200, sortable: true, locked:true, dataIndex: 'FraBancoID'},
        {header: "Localidade Agencia", width: 120, sortable: true, locked:true, align: 'right',dataIndex: 'FraCiudadSucursal'},
        {header: "Codigo de Agencia", width: 50, sortable: true, locked:true, align: 'right',dataIndex: 'FraSucursal'},
        {header: "Tipo de Conta", width: 70, sortable: true, locked:true, align: 'right',dataIndex: 'FraTipoCuenta'},
        {header: "Numero de Conta", width: 100, sortable: true, locked:true, align: 'right',dataIndex: 'FraCuenta'},
        {header: "Cota", width: 70, sortable: true, locked:true, align: 'right',dataIndex: 'FraAdcCota'},
        {header: "Cod Bem", width: 70, sortable: true, locked:true, align: 'right',dataIndex: 'FraAdcBem'},
        {header: "Grupo", width: 70, sortable: true, locked:true, align: 'right',dataIndex: 'FraAdcGroup'},
        {header: "Cambio", width: 75, sortable: true, locked:true, align: 'right',dataIndex: 'FraTasa'},
        {header: "Taxa", width: 75, sortable: true, locked:true, align: 'right',dataIndex: 'FraCargo'},
        {header: "Enviado", width: 75, sortable: true, locked:true, align: 'right',dataIndex: 'FraEnviado'},
        {header: "A Pagar", width: 75, sortable: true, locked:true, align: 'right',dataIndex: 'FraARecibir'},
        {header: "Data", width: 120, sortable: true, locked:true, renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s'),dataIndex: 'Data'},
        {header: "Urgente", width: 75, sortable: true, locked:true, align: 'right',dataIndex: 'FraUrgente'},
        {header: "Estado", width: 75, sortable: true, locked:true, align: 'right',dataIndex: 'FraStatus'}
    ]);
	Bars = new Ext.Toolbar({ 
		height:28,		
		store: this.store, 
		items : ["A pagamento: <?php echo $CGET;?> Pagamentos, EUR: <?php echo number_format($TotalPay,2);?>"," | Seleccionado: 0 | ",{
					type:'button',
					loadMask: true,
					text:'Exportar Extracto PDF',
					handler:function(){
						window.open('Aplications/Export_Pdf.mex?MOD=FTK9D4D0&ID=05&OB=<?php echo $_POST['extbnfAccount'];?>&TS=<?php echo $_POST['extbnf_DateStart'];?>&TE=<?php echo $_POST['extbnf_DateEnd'];?>','newwin');
						}
				},"<div id=rsActionResponse style=float:right></div>"]
	});

   var selmode = new Ext.grid.RowSelectionModel({});
   var Console = new Ext.grid.GridPanel({
        height: windowHeight,
		width: windowWidth-37,
        ds: ds,
	    cm: colModel,
	    sm: selmode,
				listeners: {
	 				rowdblclick: function(ds, row) { 
					var record = ds.getStore().getAt(row);
  					var value = record.get('FraID');	
					menuwindow('Operativo','_response/call.php?get=Operative/pp_frm&OR='+value,800,520,'MnMain');
					}
				},
	    bbar: Bars,
        renderTo: 'rsDisplay'
    });	
});
</script>